"""
保险公司数据库模型
"""
import uuid

from tortoise import Model, fields

from app.models.products import Products


class InsuranceCompany(Model):
    """
    保险公司表
    """
    company_id = fields.CharField(pk=True, default=lambda: str(uuid.uuid4())[:15],
                                  generated=False, max_length=15,
                                  unique=True, description="保险公司编号")
    company_name = fields.CharField(max_length=128, unique=True, description="保险公司名称")
    address = fields.CharField(default=None, max_length=255, null=True, description="地址")
    phone = fields.CharField(default=None, max_length=20, null=True, description="联系方式")
    email = fields.CharField(default=None, max_length=128, null=True, description="邮箱")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_at = fields.DatetimeField(auto_now=True, description="更新时间")
    # 反向关系定义（如果在 Products 模型中有外键指向 InsuranceCompany)
    products: fields.ReverseRelation["Products"]  # 每个保险公司有多个保险产品

    class Meta(Model.Meta):
        table = "insurance_company"
        table_description = "保险公司表"
        ordering = ["-updated_at"]  # 按照公司编号排序
